// #ifndef VUE3
import Vue from 'vue'
// 引入vuex库
import Vuex from 'vuex'
// 使用vuex
Vue.use(Vuex)
//引入vuex
import store from 'store/index.js'
//把vuex定义成全局组件
Vue.prototype.$store = store

import App from './App'
import http from './api/request.js'

import mixin from './mixin/themeMixin.js'
Vue.use(mixin)


import uView from '@/node_modules/uview-ui'
Vue.use(uView)
// 全局登录拦截器
Vue.prototype.checkLogin = function() { //判断用户是否已登录
	if (!uni.getStorageSync('token')) { //没有登录，跳转至登录页
		uni.navigateTo({
			url: '/pages/Login/Login'
		})
		return false
	} else {
		return true
	}
}
// 失败提示
const errorToast = str => {
	return new Promise((resolve, reject) => {
		uni.showToast({
			title: str,
			icon: "none",
			duration: 2000,
			success: () => {
				setTimeout(() => {
					resolve
				}, 2000)
			}
		})
	})
};
// 成功提示
const sucessToast = str => {
	return new Promise((resolve, reject) => {
		uni.showToast({
			title: str,
			icon: "success",
			duration: 2000,
			success: () => {
				setTimeout(() => {
					resolve()
				}, 2000)
			}
		})
	})
};

Vue.prototype.$sucessToast = sucessToast
Vue.prototype.$errorToast = errorToast



// 引入日期格式化插件
import moment from "@/utils/moment/index.js"
Vue.prototype.$moment = moment

// 引入公共工具js
import utils from '@/utils/utils.js'
Vue.prototype.$utils = utils

// 引入公共上传组件
import upload from '@/utils/upload.js'
Vue.prototype.$upload = upload



// 引用公共表单校验
import validate from '@/utils/validate.js'
Vue.prototype.$rules = validate

// 引入公共页面跳转组件
import pageChange from '@/utils/pageChange.js'
Vue.prototype.$pageUrl = pageChange

// 挂载公共弹出层组件
import popUpCom from '@/components/popUpCom.vue'
Vue.component('popUpCom', popUpCom)

// 引入公共加载组件
import LoadingMore from '@/components/uni-load-more.vue'
Vue.component('LoadingMore', LoadingMore)

// 引入公共头部组件
// 注册 customNavbar 组件
import customNavbar from '@/components/customNavbar/customNavbar.vue'
Vue.component('customNavbar', customNavbar)
// 引入公共提示框
import funToast from '@/utils/toast.js'


// 传入城市递归数组  返回 名称
const getDicNames = (ids, list, type) => {
	const result = []
	for (const item of list) {
		if (ids.includes(item.Id)) {
			result.push(item.DicName)
			if (item.children) {
				for (const child of item.children) {
					if (ids.includes(child.Id)) {
						result.push(child.DicName)
						if (child.children) {
							for (const children of child.children) {
								if (ids.includes(children.Id)) {
									result.push(children.DicName)
								}
							}
						}
					}
				}
			}
		}
	}

	return result
}

Vue.prototype.$getDicNames = getDicNames
// 对象数组去重
const uniqueMultiPropertyArray = (arr) => {
	const uniqueArr = arr.filter((item, index, self) => {
		return index === self.findIndex((obj) => obj.Id === item.Id)
	})

	return uniqueArr
}
Vue.prototype.$uniqueMultiPropertyArray = uniqueMultiPropertyArray

// 返回包含的对象数组  传入  两个数组  list数组是原数据数组  arr数组是参数值数组
//返回字符串
const getMatchingObjects = (arr, list) => {
	const result = []
	for (const item of list) {
		if (arr.includes(item.value)) {
			result.push(item)
		}
	}
	return result.map((v) => {
		return v['text']
	})
}
// 返回数组
const getMatchingObjectsArr = (arr, list) => {
	const result = []
	for (const item of list) {
		if (arr.includes(item.value)) {
			result.push(item)
		}
	}
	return result
}
// 返回字符串名字
Vue.prototype.$getMatchingObjects = getMatchingObjects
// 返回数组
Vue.prototype.$getMatchingObjectsArr = getMatchingObjectsArr


Vue.prototype.$funToast = funToast
// 公共url  上传附件  包括报销流程上传路径
const ActionUrl = "http://121.36.26.224:10001"
Vue.prototype.$ActionUrl = ActionUrl

// const ExcelUrl = "http://121.36.26.224:9101/MobileApp/Excel?ReportName="
const ExcelUrl = "http://192.168.1.224:81/MobileApp/Excel?ReportName="
Vue.prototype.$ExcelUrl = ExcelUrl
// import uView from "@/plugin/uview-ui";
Vue.config.productionTip = false
Vue.prototype.$http = http
const msg = (title, duration = 2000, mask = false, icon = "none") => {
	if (Boolean(title) === false) {
		return
	}
	uni.showToast({
		title,
		duration,
		mask,
		icon
	})
}
Vue.prototype.$api = {
	msg
};
// const  hasPermission = (permission) => {
//       return this.permissions.includes(permission)
//     }
// Vue.prototype.hasPermission = {
// 	hasPermission
// };

App.mpType = 'app'

const app = new Vue({
	...App,
	//挂载
	store
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
import App from './App.vue'
export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif